Clustering and Classification of Satellite Imagery

Unsupervised Clustering

This section will use unsupervised clustering to split up given satellite images into several groups, with the goal of identifying meaningfull clusters that represent different geographic features such as water, farm land, forest or buildings.

## Loading required package: randomForest
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'randomForest'
rasterJ<-brick("C:\\Users\\Owner\\Documents\\Portugal\\Sat_Image_Classification\\data\\data\\img\\J_04AUG14112729-M2AS-000000137917_01_P001_etrs89.TIF")
#rasterJ<-brick("C:\\Users\\D059331\\Desktop\\DM GIC\\data\\img\\J_04AUG14112729-M2AS-000000137917_01_P001_etrs89.TIF")
rasterJ
## class       : RasterBrick 
## dimensions  : 4238, 4239, 17964882, 4  (nrow, ncol, ncell, nlayers)
## resolution  : 2.4, 2.4  (x, y)
## extent      : -105092.3, -94918.74, -50088.84, -39917.64  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=tmerc +lat_0=39.66825833333333 +lon_0=-8.133108333333334 +k=1 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs 
## data source : C:\Users\Owner\Documents\Portugal\Sat_Image_Classification\data\data\img\J_04AUG14112729-M2AS-000000137917_01_P001_etrs89.TIF 
## names       : J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.1, J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.2, J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.3, J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.4 
## min values  :                                                  0,                                                  0,                                                  0,                                                  0 
## max values  :                                                255,                                                255,                                                255,                                                255
plotRGB(rasterJ, 3,2,1)

ext <- extent(-104294.4, -102964.5, -43623.48, -42742.44 )
sector <- crop(rasterJ, ext)
plotRGB(sector, 3, 2, 1)

sector[[5]] <- normdiff(sector)
plot(sector)

summary(sector)
##         J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.1
## Min.                                                    23
## 1st Qu.                                                 31
## Median                                                  34
## 3rd Qu.                                                 40
## Max.                                                   176
## NA's                                                     0
##         J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.2
## Min.                                                    26
## 1st Qu.                                                 40
## Median                                                  50
## 3rd Qu.                                                 65
## Max.                                                   255
## NA's                                                     0
##         J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.3
## Min.                                                     8
## 1st Qu.                                                 17
## Median                                                  34
## 3rd Qu.                                                 51
## Max.                                                   194
## NA's                                                     0
##         J_04AUG14112729.M2AS.000000137917_01_P001_etrs89.4      values
## Min.                                                     4 -0.64885496
## 1st Qu.                                                 10 -0.20000000
## Median                                                  53  0.05645161
## 3rd Qu.                                                 70  0.15384615
## Max.                                                   191  0.76870748
## NA's                                                     0  0.00000000
sector_mod <- brick(sector[[4]],sector[[5]])
performKMeans(sector_mod, 12)

K-Means doesnt seem to perform very well on this sector. Ocean and land arent clearly separated. Maybe this works better with fewer clusters (i.e. lower k).

performKMeans(sector_mod, 6)

Lets try instead a different sector, one without ocean.

ext <- extent(-101751, -100703.7, -47812.61, -46914.94)
landSector <- crop(rasterJ, ext)
landSector[[5]] <- normdiff(landSector)
plotRGB(landSector, 3, 2, 1)

landSector_mod <- brick(landSector[[4]],landSector[[5]])
performKMeans(landSector_mod, 12)

This is not too awesome. Try 6 clusters.

performKMeans(landSector_mod, 12)